package com.timothy.business.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.timothy.dao.entity.IdeaRole;
import com.timothy.dao.entity.IdeaUserRole;
import com.timothy.dao.service.IIdeaRoleService;
import com.timothy.dao.service.IIdeaUserRoleService;

@Service
public class RoleDaoService {

	@Autowired
	private IIdeaRoleService roleService;
	@Autowired
	private IIdeaUserRoleService userRoleService;

	/**
	 * 获取用户的角色信息
	 * @param userId
	 * @return
	 */
	public IdeaRole getRoleByUserId(int userId) {
		Wrapper<IdeaUserRole> userRoleWrapper = new EntityWrapper<IdeaUserRole>().eq(IdeaUserRole.ID, userId);
		IdeaUserRole userRole = userRoleService.selectOne(userRoleWrapper);
		if (userRole == null) {
			return null;
		}
		Wrapper<IdeaRole> roleWrapper = new EntityWrapper<IdeaRole>().eq(IdeaRole.ROLE_ID, userRole.getRoleId());
		IdeaRole role = roleService.selectOne(roleWrapper);
		return role;
	}
}
